<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui" 
      xmlns:f="http://java.sun.com/jsf/core">
    <ui:composition template="/resources/templates/template_site.xhtml">
        <ui:define name="content">
            <p:layout  style="min-height: 100%; max-height: 100%">
                <p:layoutUnit position="north" style="text-align: center ;min-height: 240px" header="#{menuController.item.nomitem}">
                    <p:imageSwitch effect="zoom" style="margin-left: 410px; margin-right: 400px; margin-bottom: -8000px">
                        <ui:repeat value="#{menuController.photosId}" var="image">  
                            <p:graphicImage value="#{photosStreamer.fileContent}" style="max-height: 200px">
                                <f:param name="_id" value="#{image}" />
                            </p:graphicImage>  
                        </ui:repeat>  
                    </p:imageSwitch>
                </p:layoutUnit>
                <p:layoutUnit position="center" >
                    <p:tabView id="tabView" effect="fade" effectDuration="normal" cache="false" dynamic="true">  
                        <p:tab id="tab1" title="#{bundle.DescriptionAndQuantity}" rendered="#{!utilLogin.admin}">  
                                <h:panelGrid columns="2" style="text-align: left" cellpadding="10px">
                                <h:outputText value="#{bundle.CreateItemLabel_category}" style="font-weight: bold"/>
                                <h:outputText value="#{menuController.item.category}" />
                                <h:outputText value="#{bundle.CreateItemLabel_descdetail}" style="font-weight: bold"/>
                                <h:outputText value="#{menuController.item.descdetail}" />                               
                                <h:outputText value="#{bundle.CreateItemLabel_quantiteitem}" style="font-weight: bold; max-width: 100px;" />
                                <h:outputText value="#{menuController.item.quantiteitem}" />
                            </h:panelGrid>  
                        </p:tab>  
                        <p:tab id="tab5" title="#{bundle.EditItemTitle}" rendered="#{utilLogin.admin}"> 
                            <h:panelGrid columns="1">
                                <p:messages showDetail="false" showSummary="true" id="messagePanel" autoUpdate="false" />
                                <p:panelGrid columns="2" >
                                    <h:outputText value="#{bundle.CreateItemLabel_nomitem}" style="font-weight: bold"/>
                                    <p:inplace effectSpeed="fast" event="dblclick">
                                        <p:inputText value="#{menuController.editedItem.nomitem}"/>
                                    </p:inplace>                                        
                                    <h:outputLabel value="#{bundle.CreateItemLabel_quantitecommande}"  style="font-weight: bold" />
                                    <p:inplace effectSpeed="fast" event="dblclick">
                                        <p:inputText value="#{menuController.editedItem.quantitecommande}" />
                                    </p:inplace>
                                    <h:outputLabel value="#{bundle.CreateItemLabel_seuilmin}"  style="font-weight: bold"/>
                                    <p:inplace effectSpeed="fast" event="dblclick">
                                        <p:inputText value="#{menuController.editedItem.seuilmin}" />
                                    </p:inplace>
                                    <h:outputText value="#{bundle.CreateItemLabel_category}" style="font-weight: bold"/>
                                    <p:inplace  effectSpeed="fast" event="dblclick">  
                                        <p:selectOneMenu value="#{menuController.editedItem.category}" >
                                            <f:selectItems value="#{categoryController.itemsAvailableSelectOne}"/> 
                                        </p:selectOneMenu>
                                    </p:inplace>  
                                    <h:outputText value="#{bundle.CreateItemLabel_desccourte}" style="font-weight: bold"/>
                                    <p:inplace effectSpeed="fast" event="dblclick">
                                        <p:inputText value="#{menuController.editedItem.desccourte}" />
                                    </p:inplace>
                                    <h:outputText value="#{bundle.CreateItemLabel_descdetail}" style="font-weight: bold"/>
                                    <p:inplace effectSpeed="fast" event="dblclick">
                                        <p:inputTextarea value="#{menuController.editedItem.descdetail}" maxlength="255"/>
                                    </p:inplace>
                                </p:panelGrid>  
                                <p:commandButton value="Confirmer les changements" actionListener="#{menuController.confirmChanges()}" update="messagePanel,tab5,tabView" />
                            </h:panelGrid>
                        </p:tab>  

                        <p:tab id="tab2" title="Caractéristiques" rendered="#{!utilLogin.admin}">  
                            <p:dataTable value="#{menuController.caracteristiques}"  var="caracteristique" style="text-align: left; max-width: 300px" >
                                <p:column >
                                    <f:facet name="header" >
                                        <h:outputText value="#{bundle.NomCaracteristique}" />
                                    </f:facet>
                                    <h:outputText value="#{caracteristique.nomcarac} "  />                                
                                </p:column>
                                <p:column >
                                    <f:facet name="header" >
                                        <h:outputText value="#{bundle.Description}" />
                                    </f:facet>
                                    <h:outputText value="#{caracteristique.decription}" />                                    
                                </p:column>
                            </p:dataTable>
                            <p:panelGrid columns="2"  style="text-transform: capitalize; font-size: 14px; text-align: center">  
                                <h:outputLabel value="Prix :" />
                                <h:outputText value="#{menuController.prix} DT" style="font-style: italic;font-weight: bold" />
                            </p:panelGrid>  
                        </p:tab>  
                        <p:tab id="tab6" title="Caractéristiques " rendered="#{utilLogin.admin}">  

                            <h:panelGrid columns="3">
                                <p:panel header="#{bundle.CreateCaracteristiqueTitle}">  
                                    <p:panelGrid columns="2" id="grid">  
                                        <h:outputLabel value="#{bundle.ViewCaracteristiqueLabel_nomcarac}" for="txt_title"></h:outputLabel>  
                                        <p:inputText id="txt_title"   
                                                     value="#{caracteristiqueController.newCaracteristique.nomcarac}" />  

                                        <h:outputLabel value="#{bundle.ViewCaracteristiqueLabel_decription}" for="txt_author"></h:outputLabel>  
                                        <p:inputText id="txt_author"  
                                                     value="#{caracteristiqueController.newCaracteristique.decription}" />  

                                        <p:commandButton value="Annuler" type="reset"/>  
                                        <p:commandButton id="btn_add" value="Ajouter" update="carac @parent" actionListener="#{caracteristiqueController.reinit()}" >  
                                            <f:param name="item" value="#{menuController.item.iditem}" />
                                            <p:collector value="#{caracteristiqueController.newCaracteristique}"   
                                                         addTo="#{menuController.caracteristiques}" /> 
                                        </p:commandButton>  
                                    </p:panelGrid>  
                                </p:panel>
                                <p:dataTable value="#{menuController.caracteristiques}" id="carac"  var="caracteristique" style="text-align: left; max-width: 300px" >
                                    <p:column >
                                        <f:facet name="header" >
                                            <h:outputText value="#{bundle.NomCaracteristique}" />
                                        </f:facet>
                                        <h:outputText value="#{caracteristique.nomcarac} "  />                                
                                    </p:column>
                                    <p:column >
                                        <f:facet name="header" >
                                            <h:outputText value="#{bundle.Description}" />
                                        </f:facet>
                                        <h:outputText value="#{caracteristique.decription}" />                                    
                                    </p:column>
                                </p:dataTable>

                            </h:panelGrid>
                        </p:tab> 

                        <p:tab id="tab3" title="#{bundle.AjouterPanier}" disabled="#{!utilLogin.connected}" rendered="#{!utilLogin.admin}">  
                            <h:panelGrid columns="1">
                                <p:messages showDetail="true" autoUpdate="true" showSummary="false" />                                
                                <h:panelGrid columns="3" cellpadding="10">  
                                    <h:outputLabel value="#{bundle.CommandeQuantite}" />
                                    <p:spinner id="minmax"   
                                               value="#{utilLogin.quantite}" min="0" max="#{menuController.item.quantiteitem}" validatorMessage="#{bundle.MsgQuantite} #{menuController.item.quantiteitem}">
                                        <f:validateLongRange minimum="0" maximum="#{menuController.item.quantiteitem}" />
                                    </p:spinner>  
                                    <p:commandButton onclick="(#{utilLogin.util.typeclient != 'Inscrit'})? confirmDialog.show():inscritDialog.show()" value="confirm"  type="button" >
                                    </p:commandButton>
                                </h:panelGrid>  
                            </h:panelGrid>
                        </p:tab>  

                        <p:tab title="Changer le prix" rendered="#{utilLogin.admin}">
                            <div>   
                                <h:panelGrid columns="1" >
                                    <p:messages showDetail="true" autoUpdate="false" showSummary="false" id="prixMes"/>                                                                
                                    <p:panel header="#{bundle.ChangePrix}" id="prixPanel">
                                        <p:panelGrid columns="1">
                                            <p:inputText value="#{prixController.somme}" />
                                            <p:commandButton actionListener="#{prixController.createNew}" value="Changer" update="prixPanel, prixMes" >
                                                <f:param name="item" value="#{menuController.item.iditem}" />
                                            </p:commandButton>
                                        </p:panelGrid>                                                                        
                                    </p:panel>
                                    <h:panelGrid columns="2" style="margin-left: 80px; font-weight: bold">
                                        <h:outputLabel value="Prix :"/>
                                        <h:outputLabel value="#{menuController.prix} DT" />
                                    </h:panelGrid>
                                </h:panelGrid>
                            </div>

                        </p:tab>

                        <p:tab id="tab4" title="Ajouter une photo" rendered="#{utilLogin.admin}">                              
                            <p:growl showDetail="true" autoUpdate="false" showSummary="false" id="growl"/>
                            <h:panelGrid columns="2" cellpadding="10">  
                                <h:outputLabel value="#{bundle.CreatePhotosLabel_photo}" for="photo" />
                                <p:fileUpload label="Choisir" cancelLabel="Annuler" uploadLabel="Charger" fileUploadListener="#{photosController.processFileUpload}" mode="advanced" 
                                              allowTypes="/(\.|\/)(gif|jpeg|png)$/" sizeLimit="1000000" id="photo"/>                                    
                                <f:facet name="footer">  
                                    <p:commandButton actionListener="#{photosController.create}" value="Ajouter" id="ajouter" update="growl" icon="ui-icon-check" style="margin-left: 370px">  
                                        <f:param name="item" value="#{menuController.item.iditem}" />
                                    </p:commandButton>
                                </f:facet>
                            </h:panelGrid>                              
                        </p:tab> 

                        <p:tab id="fournisseur" title="Fournisseur" rendered="#{utilLogin.admin}">                                                 
                            <p:tabView effect="fade" effectDuration="normal" cache="false" dynamic="true">                                                                
                                <p:ajax event="tabChange" listener="#{fournisseurController.onTabChange}" immediate="true" update="A,B,siteweb"/>  
                                <p:tab title="Fournisseur Leader"> 
                                    <h:panelGrid columns="1">
                                        <p:messages showDetail="true" autoUpdate="false" showSummary="false" id="fourLeadMes"/>
                                        <h:outputText value="#{menuController.fournisseurLeader}" id="leader" style="font-weight: bold"/>
                                        <p:panelGrid columns="2" id="A" rendered="#{!itemController.chooseFour}">
                                            <h:outputText value="Choisir le fournisseur leader: " />  
                                            <p:selectOneMenu value="#{fournisseurController.fournisseur}">  
                                                <f:selectItem itemLabel="--Choisir---"/>
                                                <f:selectItems value="#{menuController.listFournisseur}" var="fournisseur" itemLabel="#{fournisseur.nomfour}"/>
                                            </p:selectOneMenu>
                                            <p:commandButton value="Confirmer" actionListener="#{fournisseurController.setLeader}" update="fourLeadMes, leader">
                                                <f:param name="item" value="#{menuController.item.iditem}" />
                                            </p:commandButton>
                                        </p:panelGrid>
                                    </h:panelGrid>
                                </p:tab>                                
                                <p:tab title="Ajouter un Nouveau Fournisseur" >
                                    <h:panelGrid columns="1">
                                        <p:messages showDetail="true" autoUpdate="false" showSummary="false" id="fourMes"/>
                                        <p:panelGrid columns="2" id="B" rendered="#{!itemController.chooseFour}">
                                            <h:outputLabel value="#{bundle.CreateFournisseurLabel_telfour}" for="telfour" />
                                            <p:inputMask mask="(999) 99 999 999" id="telfour" value="#{fournisseurController.selected.telfour}" title="#{bundle.CreateFournisseurTitle_telfour}" requiredMessage="#{bundle.CreateFournisseurRequiredMessage_telfour}"/>
                                            <h:outputLabel value="#{bundle.CreateFournisseurLabel_siteweb}" for="siteweb" />
                                            <p:inputText id="siteweb" value="#{fournisseurController.selected.siteweb}" title="#{bundle.CreateFournisseurTitle_siteweb}" />
                                            <h:outputLabel value="#{bundle.CreateFournisseurLabel_nomfour}" for="nomfour" />
                                            <p:inputText id="nomfour" value="#{fournisseurController.selected.nomfour}" title="#{bundle.CreateFournisseurTitle_nomfour}" requiredMessage="#{bundle.CreateFournisseurRequiredMessage_nomfour}"/>
                                            <h:outputLabel value="#{bundle.CreateFournisseurLabel_adressefour}" for="adressefour" />
                                            <p:inputText id="adressefour" value="#{fournisseurController.selected.adressefour}" title="#{bundle.CreateFournisseurTitle_adressefour}" requiredMessage="#{bundle.CreateFournisseurRequiredMessage_adressefour}"/>                                        
                                        </p:panelGrid>
                                        <p:commandButton value="Ajouter fournisseur" action="#{fournisseurController.create}" update="fourMes,B">
                                            <f:param name="item" value="#{menuController.item.iditem}" />
                                        </p:commandButton>
                                    </h:panelGrid>
                                </p:tab>                                                                  
                            </p:tabView>                                                     
                        </p:tab>
                        <p:tab title="Evolution du prix">
                            <p:lineChart id="linear" value="#{menuController.categoryModel}"  
                                         title="Evolution du prix"  style="height:150px" minY="0" yaxisLabel="Prix en DT"/>   
                            <br/>
                            <p:lineChart  value="#{menuController.priceChartModel}"  
                                         title="Evolution du Nombre de vente en fonction des changements du prix"  style="height:150px" minY="0" yaxisLabel="Nombre de vente"/> 
                        </p:tab>
                    </p:tabView>
                </p:layoutUnit>
            </p:layout>
            <p:dialog widgetVar="inscritDialog" >
                <p:panelGrid columns="2">
                    <h:outputText value="#{bundle.Phone}"/>
                    <p:inputMask value="#{utilLogin.util.tel}"   
                                 mask="(+999) 99-999-999" />                                
                    <p:commandButton value="Confirmer les changements et reservet" oncomplete="inscritDialog.hide()"  action="#{utilLogin.confirmChangesAndReservation()}" >
                        <f:param name="item" value="#{menuController.item.iditem}" />                        
                    </p:commandButton>
                </p:panelGrid>
            </p:dialog>
            <p:confirmDialog widgetVar="confirmDialog" message="Confirmer la reservation?" header="Confirmation de la reservation" severity="alert">
                <p:commandButton  style="margin-left: 30px" value="Oui"  oncomplete="confirmDialog.hide()"  
                                  actionListener="#{utilLogin.commander()}" >
                    <f:param name="item" value="#{menuController.item.iditem}" />
                </p:commandButton>  
                <p:commandButton  style="margin-left: 80px" value="Non" onclick="confirmation.hide()" type="button" /> 
            </p:confirmDialog>
        </ui:define>
    </ui:composition>
</html>
